package com.wngz;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wngz.entity.Employee;
import com.wngz.entity.User;
import com.wngz.mapper.EmployeeMapper;
import com.wngz.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.StringUtils;

import java.util.List;

@SpringBootTest
public class UserMapperTest03 {

    @Autowired
    private EmployeeMapper employeeMapper;



    // 查询薪水大于等于5000且所在部门为销售部的员工，并按薪水降序排序。
    @Test
    public void query01(){

        LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        lambdaQueryWrapper.gt(Employee::getSalary,5000.00)
                .eq(Employee::getDepart,"销售部")
                .orderByDesc(Employee::getSalary);

        List<Employee> employees = employeeMapper.selectList(lambdaQueryWrapper);
        employees.forEach(System.out::println);
    }




    //2. 查询性别为男且所在部门以"人"开头的员工信息。
    @Test
    public void query02(){
        LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        lambdaQueryWrapper.eq(Employee::getSex,"男")
                        .likeRight(Employee::getDepart,"人");

        List<Employee> employees = employeeMapper.selectList(lambdaQueryWrapper);
        employees.forEach(System.out::println);
    }


    //查询薪水在5000到10000之间，且所在部门不是"开发部"的员工信息。
    @Test
    public void query03(){
        LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        lambdaQueryWrapper.between(Employee::getSalary,5000.00,10000.00)
                        .ne(Employee::getDepart,"开发部");

        List<Employee> employees = employeeMapper.selectList(lambdaQueryWrapper);
        employees.forEach(System.out::println);
    }



    //查询姓氏以"白"或"孙"开头且薪水不在2000到5000之间的员工信息。
    @Test
    public void query04(){
        LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        lambdaQueryWrapper.and(
                e -> e.likeRight(Employee::getName,"白")
                        .or().likeRight(Employee::getName,"孙"))
                .notBetween(Employee::getSalary,2000.00,5000.00);

        List<Employee> employees = employeeMapper.selectList(lambdaQueryWrapper);
        employees.forEach(System.out::println);
    }

}
